import table from '@/components/dt/table/render.js'
import Opt from '@/components/dt/info/Opt.js'

let _this = null
let labelObj1 = {
  CLUETARGET: '线索',
  VISITOR: '来人',
  SUBSCRIPTION: '认购',
  CONTRACT: '签约',
  PAYMENT: '回款'
}
class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    let monthList = [
      {
        field: 'month',
        title: '月份',
        minWidth: 130
      }
    ]
    let handleList = [
      {
        field: 'stateStr',
        title: '设定状态',
        minWidth: 130
      },
      {
        title: '操作人',
        minWidth: 130,
        cell: (info) => {
          return {
            value: (info) => {
              return `${info.updateName ? info.updateName + '(' + info.workNo + ')' : '-'}`
            },
            text: {}
          }
        }
      },
      {
        field: 'handles',
        title: '操作项',
        fixed: 'right',
        minWidth: 180,
        align: 'center',
        cell: (row) => {
          let btn = [
            {
              title: '查看目标',
              event: 'checkDetail',
              visible: row.state != 2
            },
            {
              title: '设定目标',
              event: 'setGoal',
              code: '0102010601',
              visible: row.state == 1
            },
            {
              title: '调整目标',
              event: 'adjustGoal',
              code: '0102010602',
              visible: row.state == 3
            },
            {
              title: '补设目标',
              event: 'setGoal',
              code: '0102010601',
              visible: row.state == 2
            }
          ]
          return { btn }
        }
      }
    ]
    let clueOrVisitorList = [
      {
        title: `案场${labelObj1[_this.curState]}目标`,
        align: 'center',
        children: [
          {
            field: `clueTarget`,
            title: `初始目标(组)`,
            minWidth: 150,
            cell: {
              value: (row) => {
                return `${row.clueTarget || row.clueTarget == 0 ? row.clueTarget : '-'}${
                  row.clueTarget && row.whether ? '(补设)' : ''
                }`
              },
              text: {}
            }
          },
          {
            field: 'adjustmentTarget',
            title: `调整目标(组)`,
            minWidth: 150
          },
          {
            field: 'diff',
            title: `调整差(组)`,
            minWidth: 150,
            slots: {
              default: (params, h) => {
                let diffValue = params.row.diff || params.row.diff == 0 ? params.row.diff : '-'
                let color = diffValue > 0 ? '#D9001B' : diffValue < 0 ? '#70B603' : '#515a6e'
                let priceDVTmp = diffValue > 0 ? '+' + diffValue : diffValue < 0 ? diffValue : diffValue
                return table.cell.text(h, {
                  value: `<span style=color:${color};margin-left:5px>${priceDVTmp}</span>`,
                  isHtml: true,
                  tipsTxt: diffValue
                })
              }
            }
          }
        ]
      },
      {
        field: 'advisorTarget',
        title: `顾问${labelObj1[_this.curState]}目标(组)`,
        minWidth: 180
      }
    ]
    let subOrContractList = [
      {
        title: `案场${labelObj1[_this.curState]}套数目标`,
        align: 'center',
        children: [
          {
            field: 'countInitUnit',
            title: `初始目标(套)`,
            minWidth: 150,
            cell: {
              value: (row) => {
                return `${row.countInitUnit || row.countInitUnit == 0 ? row.countInitUnit : '-'}${
                  row.countInitUnit && row.whether ? '(补设)' : ''
                }`
              },
              text: {}
            }
          },
          {
            field: 'countCurrentUnit',
            title: `调整目标(套)`,
            minWidth: 150
          },
          {
            title: `调整差(套)`,
            minWidth: 150,
            slots: {
              default: (params, h) => {
                let diffValue =
                  params.row.countDvalue || params.row.countDvalue == 0 ? params.row.countDvalue : '-'
                let color = diffValue > 0 ? '#D9001B' : diffValue < 0 ? '#70B603' : '#515a6e'
                let priceDVTmp = diffValue > 0 ? '+' + diffValue : diffValue < 0 ? diffValue : diffValue
                return table.cell.text(h, {
                  value: `<span style=color:${color};margin-left:5px>${priceDVTmp}</span>`,
                  isHtml: true,
                  tipsTxt: diffValue
                })
              }
            }
          }
        ]
      },
      {
        title: `案场${labelObj1[_this.curState]}金额目标`,
        align: 'center',
        children: [
          {
            field: 'moneyInitUnit',
            title: `初始目标(万)`,
            minWidth: 150,
            cell: {
              value: (row) => {
                return `${row.moneyInitUnit || row.moneyInitUnit == 0 ? row.moneyInitUnit : '-'}${
                  row.moneyInitUnit && row.whether ? '(补设)' : ''
                }`
              },
              text: {}
            }
          },
          {
            field: 'moneyCurrentUnit',
            title: `调整目标(万)`,
            minWidth: 150
          },
          {
            title: `调整差(万)`,
            minWidth: 150,
            slots: {
              default: (params, h) => {
                let diffValue =
                  params.row.moneyDvalue || params.row.moneyDvalue == 0 ? params.row.moneyDvalue : '-'
                let color = diffValue > 0 ? '#D9001B' : diffValue < 0 ? '#70B603' : '#515a6e'
                let priceDVTmp = diffValue > 0 ? '+' + diffValue : diffValue < 0 ? diffValue : diffValue
                return table.cell.text(h, {
                  value: `<span style=color:${color};margin-left:5px>${priceDVTmp}</span>`,
                  isHtml: true,
                  tipsTxt: diffValue
                })
              }
            }
          }
        ]
      },
      {
        title: `案场${labelObj1[_this.curState]}面积目标`,
        align: 'center',
        children: [
          {
            field: 'areaInitUnit',
            title: `初始目标(㎡)`,
            minWidth: 150,
            cell: {
              value: (row) => {
                return `${row.areaInitUnit || row.areaInitUnit == 0 ? row.areaInitUnit : '-'}${
                  row.areaInitUnit && row.whether ? '(补设)' : ''
                }`
              },
              text: {}
            }
          },
          {
            field: 'areaCurrentUnit',
            title: `调整目标(㎡)`,
            minWidth: 150
          },
          {
            title: `调整差(㎡)`,
            minWidth: 150,
            slots: {
              default: (params, h) => {
                let diffValue =
                  params.row.areaDvalue || params.row.areaDvalue == 0 ? params.row.areaDvalue : '-'
                let color = diffValue > 0 ? '#D9001B' : diffValue < 0 ? '#70B603' : '#515a6e'
                let priceDVTmp = diffValue > 0 ? '+' + diffValue : diffValue < 0 ? diffValue : diffValue
                return table.cell.text(h, {
                  value: `<span style=color:${color};margin-left:5px>${priceDVTmp}</span>`,
                  isHtml: true,
                  tipsTxt: diffValue
                })
              }
            }
          }
        ]
      },
      {
        title: `顾问目标`,
        align: 'center',
        children: [
          {
            field: 'adviserCount',
            title: `顾问${labelObj1[_this.curState]}套数(套)`,
            minWidth: 150
          },
          {
            field: 'adviserMoney',
            title: `顾问${labelObj1[_this.curState]}金额(万)`,
            minWidth: 150
          },
          {
            field: 'adviserArea',
            title: `顾问${labelObj1[_this.curState]}面积(㎡)`,
            minWidth: 150
          }
        ]
      }
    ]
    let paymentList = [
      {
        title: `案场回款目标`,
        align: 'center',
        children: [
          {
            field: 'clueTarget',
            title: `初始目标(万)`,
            minWidth: 150,
            cell: {
              value: (row) => {
                return `${row.clueTarget || row.clueTarget == 0 ? row.clueTarget : '-'}${
                  row.clueTarget && row.whether ? '(补设)' : ''
                }`
              },
              text: {}
            }
          },
          {
            field: 'adjustmentTarget',
            title: `调整目标(万)`,
            minWidth: 150
          },
          {
            field: 'diff',
            title: `调整差(万)`,
            minWidth: 150,
            slots: {
              default: (params, h) => {
                let diffValue = params.row.diff || params.row.diff == 0 ? params.row.diff : '-'
                let color = diffValue > 0 ? '#D9001B' : diffValue < 0 ? '#70B603' : '#515a6e'
                let priceDVTmp = diffValue > 0 ? '+' + diffValue : diffValue < 0 ? diffValue : diffValue
                return table.cell.text(h, {
                  value: `<span style=color:${color};margin-left:5px>${priceDVTmp}</span>`,
                  isHtml: true,
                  tipsTxt: diffValue
                })
              }
            }
          }
        ]
      },
      {
        field: 'advisorTarget',
        title: `顾问回款目标(万)`,
        minWidth: 180
      }
    ]
    if (_this.curState == 'CLUETARGET' || _this.curState == 'VISITOR') {
      this.all = [...monthList, ...clueOrVisitorList, ...handleList]
    } else if (_this.curState == 'SUBSCRIPTION' || _this.curState == 'CONTRACT') {
      this.all = [...monthList, ...subOrContractList, ...handleList]
    } else if (_this.curState == 'PAYMENT') {
      this.all = [...monthList, ...paymentList, ...handleList]
    }
  }
}

export default Column
